//
//  SettingsController.m
//  PapIPhone
//
//  Created by Rene Dohan on 11/08/11.
//  Copyright 2011 rensoft. All rights reserved.
//

#import "Application.h"
#import "SettingsController.h"
#import "LoginRequest.h"
#import "DSActivityView.h"


@implementation SettingsController

@dynamic username, password, url;

- (void)viewDidLoad {
    [super viewDidLoad];
    url.text = [[Application getInstance] url];
    username.text = [[Application getInstance] username];
    password.text = [[Application getInstance] password];
}

- (IBAction)saveAndConnect:(id)sender {
    NSLog(@"saveAndConnect");
    LoginRequest *request = [LoginRequest new];
    request.listener = self;
    request.url = url.text;
    request.username = username.text;
    request.password = password.text;
    [request send];
    [DSBezelActivityView newActivityViewForView:self.view];
}

- (void)onLoginSuccess:(NSString *)userType:(NSString *)session {
    [[Application getInstance] onLogin:url.text :username.text :password.text :session :userType];
    [DSActivityView removeView];
    [tabBarController setSelectedIndex:0];
}

- (void)onLoginFailed {

}

- (IBAction)textFieldBeginEditing:(UITextField *)sender {
    currentTextField = sender;
    [self textFieldDidBeginEditing:sender];
}

- (IBAction)textFieldEndEditing:(UITextField *)sender {
    [self textFieldDidEndEditing:sender];
}

- (IBAction)textFieldReturn:(id)sender {
    [sender resignFirstResponder];
}

- (IBAction)backgroundTouched:(id)sender {
    [currentTextField resignFirstResponder];
}

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
        // Custom initialization
    }
    return self;
}
*/


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return true;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
